package com.lbh.cloudgallery.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lbh.cloudgallery.entity.CommentEntity;
import com.lbh.cloudgallery.entity.vo.CommentVo;
import com.lbh.cloudgallery.service.CommentService;
import com.xxx.common.utils.PageUtils;
import com.xxx.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author 廖碧涵
 * @email lbh@qq.com
 * @date 2021-02-25 22:47:51
 */
@Api(tags = "评论")
@RestController
@RequestMapping("front/comment")
public class FrontCommentController {
    @Autowired
    private CommentService commentService;


    @ApiOperation(value = "添加评论")
    @PostMapping("/addComment")
    public R addComment(@RequestBody CommentVo commentVo){

        CommentEntity commentEntity = new CommentEntity();
        commentEntity.setMemberId(commentVo.getMemberId());
        commentEntity.setProductId(commentVo.getProductId());
        commentEntity.setGmtCreate(new Date());
        commentEntity.setContent(commentVo.getContent());

        boolean b = commentService.save(commentEntity);
        if (b){
            return R.ok().put("msg","评价成功");
        }else return R.error().put("msg","服务器繁忙，请稍后重试！");
    }


    @ApiOperation(value = "查询评论")
    @GetMapping("/getCommentList")
    public R getCommentList(@RequestParam Long productId){
        List<CommentEntity> commentEntityList = commentService.list(new QueryWrapper<CommentEntity>().eq("product_id", productId));
        return R.ok().put("data",commentEntityList);

    }
}
